<?php
/**
 * Class about culture list data providing
 * 
 * @author PoLuX
 *
 */
class Service_statutCulture extends AServiceGetInfos {

	/**
	 * Constructor by default
	 */
	public function __construct()
	{
		$this->_as_parameters = array('format','cult');
		$this->_ax_outputDataDef = array(
				"CODE","LIB","TECHCULT","PHCULT_CODE",
				"CULTPHCULT_DEBUT","CULTPHCULT_FIN",
				"NB_J_DEB_PHASE","NB_J_FIN_PHASE",
				"NB_J_DEB_CULT","NB_J_FIN_CULT","NB_PLT","PHCULT_LIB","PHCULT_NB_J","PHCULT_PH_ORDER","PHCULT_TOTAL_PH_NUMB"
				
		);
	}
	
	/**
	 * Execution du service
	 * @param unknown $p_as_parameters
	 */
	public function getData($p_as_OutputParam)
	{
		if($this->checkParametersNeeded($p_as_OutputParam))
		{
			$this->_s_format = $p_as_OutputParam['format'];
			
			$l_s_sql = "";
			MyPDODatabase::connect();
			$l_o_hdb = MyPDODatabase::getPDOConnection();
			
			try{
				// SELECT
				$l_s_sql = "SELECT ";
				foreach($this->_ax_outputDataDef as $l_s_key)
				{
					if($l_s_sql != "SELECT ")
						$l_s_sql = $l_s_sql.", ";
					$l_s_sql = $l_s_sql.$l_s_key;
				}				
				// FROM
				$l_s_sql = $l_s_sql." FROM ";
				$l_s_sql = $l_s_sql." V_CULT_CURRENT_STATUS WHERE CODE='".$p_as_OutputParam['cult']."'";
				
				$l_o_query = $l_o_hdb->prepare($l_s_sql);
				$l_o_query->execute();

			
				$this->_ax_dataResult = $l_o_query->fetchAll(PDO::FETCH_ASSOC);
				
				if(sizeof($this->_ax_dataResult)==0)
				{
					$this->_s_codeRequestResult = "NO_DATA";
					$this->_as_message[] = "No data available for Culture : ".$p_as_OutputParam['cult'];
				}
				else 
					$this->_s_codeRequestResult = "OK";
				//print_r($this->_ax_dataResult);
				//$this->_s_codeRequestResult = "OK";
			}
			catch(PDOException $e)
			{
				$this->_s_codeRequestResult = "EXCEPTION";
				$this->_o_exception = $e;
			}
		}
		else
		{
			$this->_s_codeRequestResult = "ERROR";
			$this->_as_message[] = '<BR>Les paramètres nécessaires ne sont pas présents !';
		}	
		
		return $this->getRequestOutput();
	}
	
}
?>